var common = require('../../utils/common.js');
const app = getApp()
Page({
  data: {
    nav:[
      "本月收益",
      "累计收益"
    ],
    currentTab: 0,
    incomeInfo: [],
    mouthBegin:'',
    mouthEnd: ''
  },
  onLoad: function (options) {
    this.getIncomeInfo()
    this.getDate()
  },
  navChange(e){
    console.log(e)
    console.log(e.currentTarget.dataset.current)
    this.setData({
      currentTab: e.currentTarget.dataset.current
    })
  },
  getIncomeInfo(){
    const that = this
    common.post({
      url: '/app/user/myIncomeInfo', data: { sessionId: app.globalData.sessionId }
    })
      .then((res) => {
        console.log(res.data)
        if (res.data.code == 0) {
          console.log(res.data)
          that.setData({
            incomeInfo: res.data.data
          })
        }
      }).catch((res) => {
        console.log(res)
        app.timeOutTip()
      })
  },
  getDate(){
    var now = new Date(); //当前日期
    var nowDayOfWeek = now.getDay(); //今天本周的第几天
    var nowDay = now.getDate(); //当前日
    var nowMonth = now.getMonth(); //当前月
    var nowYear = now.getYear(); //当前年
    nowYear += (nowYear < 2000) ? 1900 : 0; //
    //格式化日期：yyyy-MM-dd
    function formatDate(date) {
      var myyear = date.getFullYear();
      var mymonth = date.getMonth() + 1;
      var myweekday = date.getDate();

      if (mymonth < 10) {
        mymonth = "0" + mymonth;
      }
      if (myweekday < 10) {
        myweekday = "0" + myweekday;
      }
      return (myyear + "-" + mymonth + "-" + myweekday);
    }

    //获得某月的天数
    function getMonthDays(myMonth) {
      var monthStartDate = new Date(nowYear, myMonth, 1);
      var monthEndDate = new Date(nowYear, myMonth + 1, 1);
      var days = (monthEndDate - monthStartDate) / (1000 * 60 * 60 * 24);
      return days;
    }
    //获得本月的开始日期
    function getMonthStartDate() {
      var monthStartDate = new Date(nowYear, nowMonth, 1);
      return formatDate(monthStartDate);
    }
    var mouthBegin = getMonthStartDate()
    //获得本月的结束日期
    function getMonthEndDate() {
      var monthEndDate = new Date(nowYear, nowMonth, getMonthDays(nowMonth));
      return formatDate(monthEndDate);
    }
    var mouthEnd = getMonthEndDate()
    this.setData({
      mouthBegin: mouthBegin,
      mouthEnd: mouthEnd
    })
  },
  explain(){
    wx.showModal({
      title: '关于预估收益说明',
      content: '根据京东推广规则：预估收益是根据用户下单时间预估统计的推广效果数据，并非实际结算收益，订单取消或者退换货后对应收益会相应扣除，实际收益以订单完成结算为准。注：未付款的订单佣金不计入预估佣金中。',
      success(res) {
        if (res.confirm) {
          console.log('用户点击确定')
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  }
})